<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:api')->get('/user', function (Request $request) {
    return $request->user();
});

Route::namespace('Admin')->group(function () {
    //获取token
    Route::post('authorization', 'AuthController@store')->name('auth.authorization');
    Route::get('user/logout', 'UserController@logout')->name('user.logout');//退出登录
    Route::get('user/menu', 'UserController@getMenuList')->name('user.getMenuList');//获取此用户所拥有的菜单列表
    Route::get('user/permission', 'UserController@getPermissionList')->name('user.getPermissionList');//获取此用户所拥有的权限列表
    Route::get('user/currentShow', 'UserController@show')->name('user.show');//获取当前登录用户信息
    Route::middleware(['auth:api', 'role'])->group(function () {
        Route::post('user', 'UserController@store')->name('user.store');//添加用户
        Route::get('user', 'UserController@index')->name('user.index');//获取用户列表
        Route::delete('user/{user}', 'UserController@destroy')->name('user.destroy');//删除用户信息
        Route::post('user/{user}/role', 'UserController@changeRoleFromUser')->name('user.changeRoleFromUser');//为用户分配角色
        Route::get('permission', 'PermissionController@index')->name('permission.index');//获取权限列表
        Route::get('permission/{permission}', 'PermissionController@show')->name('permission.show');//新增权限
        Route::post('permission', 'PermissionController@store')->name('permission.store');//新增权限
        Route::delete('permission/{permission}', 'PermissionController@destroy')->name('permission.delete');//删除权限
        Route::get('role', 'RoleController@index')->name('role.index');//获取角色列表
        Route::post('role', 'RoleController@store')->name('role.store');//保存角色
        Route::delete('role/{role}', 'RoleController@destroy')->name('role.destroy');//删除角色
        Route::get('role/{role}/permission', 'RoleController@getMenusToRole')->name('role.getPermissionToRole');//获取角色拥有的权限
        Route::post('role/{role}/permission', 'RoleController@changePermissionToRole')->name('role.changePermission');//为角色新增权限
        Route::get('log', 'LogController@index')->name('log.index');//获取日志列表
    });
});
